﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OrderServiceReference;

public partial class UserControls_UpdateOrder : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;
        ddlStatus.Items.Add(new ListItem("True", "true"));
        ddlStatus.Items.Add( new ListItem("False", "false"));
        var client = new OrderServiceClient();
        GridView1.DataSource = client.GetOrders();
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        var client = new OrderServiceClient();
        GridView1.DataSource = client.GetOrders();
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            var client = new OrderServiceClient();
            var result = client.UpdateOrder(int.Parse(GridView1.SelectedRow.Cells[0].Text), bool.Parse(ddlStatus.SelectedValue));
            lblmsg.Text = result ? "Update thanh cong" : "Update that bai";
            UpdatePanel1.Update();
        }
        catch (FaultException<Order> faultException)
        {
            lblmsg.Text = faultException.Message;
        }
        catch (Exception)
        {
            lblmsg.Text = "Ban chua chon order can update";
        }
    }
}